import redis
from config import config


class RedisHandler:
    def __init__(self):
        self.conn = self.__connection()

    def __connection(self):
        redis_config = config["redis_config"]
        conn = redis.StrictRedis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"],
                                 decode_responses=True, socket_connect_timeout=3)
        return conn


if __name__ == '__main__':
    conn = RedisHandler().conn

    conn.set("z1145058527@qq.com", 2222, ex=10, nx=True)  # ex:过期时间（秒），nx为true：不存在则set操作才执行
    result = conn.get("z1145058527@qq.com")
    print(result)
    # print("over")
